<?php

declare(strict_types=1);

namespace App\CustHub\Controller;

use App\Chat\Interfaces\ChatUserAuthInterface;
use App\CustHub\Annotation\ApiAuth;
use App\CustHub\Annotation\VerifySignature;
use App\CustHub\Request\CustomerServiceRequest;
use App\CustHub\Request\LoginRequest;
use App\CustHub\Service\ChCustomerServiceService;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\PostMapping;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use Psr\Http\Message\ResponseInterface;

#[Controller('ch/customer_service'),VerifySignature,ApiAuth]
class CustomerServiceController extends BaseController
{
    #[Inject]
    protected ChCustomerServiceService $service;

    #[Inject]
    protected ChatUserAuthInterface $userAuth;



    #[PostMapping('list')]
    public function list()
    {
        return $this->success($this->service->list($this->request->all()));
    }

    /**
     * 保存
     * @param CustomerServiceRequest $request
     * @return \Psr\Http\Message\ResponseInterface
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     */
    #[PostMapping('save')]
    public function save(CustomerServiceRequest $request): \Psr\Http\Message\ResponseInterface
    {
        return $this->service->save($request->all()) ? $this->success() : $this->error();
    }

    /**
     * 详情
     * @param CustomerServiceRequest $request
     * @return \Psr\Http\Message\ResponseInterface
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     */
    #[PostMapping('detail')]
    public function detail(CustomerServiceRequest $request): \Psr\Http\Message\ResponseInterface
    {
        return $this->success($this->service->detail($request->all()));
    }

    /**
     * 修改
     * @param CustomerServiceRequest $request
     * @return \Psr\Http\Message\ResponseInterface
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     */
    #[PostMapping('update')]
    public function update(CustomerServiceRequest $request): \Psr\Http\Message\ResponseInterface
    {
        return $this->service->update($request->input('id'),$request->all()) ? $this->success() : $this->error();
    }

    /**
     * 分配客户群
     * @param CustomerServiceRequest $request
     * @return \Psr\Http\Message\ResponseInterface
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     */
    #[PostMapping('setRooms')]
    public function setRooms(CustomerServiceRequest $request): \Psr\Http\Message\ResponseInterface
    {
        return $this->service->setRooms($request->all()) ? $this->success() : $this->error();
    }

    /**
     * 删除
     * @param CustomerServiceRequest $request
     * @return \Psr\Http\Message\ResponseInterface
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     */
    #[PostMapping('delete')]
    public function delete(CustomerServiceRequest $request): \Psr\Http\Message\ResponseInterface
    {
        return $this->service->delete($request->input('ids')) ? $this->success() : $this->error();
    }

    /**
     * 自动登录
     * @param LoginRequest $request
     * @return ResponseInterface
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    #[PostMapping('autoLogin')]
    public function autoLogin(LoginRequest $request): ResponseInterface
    {
        return $this->success($this->userAuth->autoLogin($request->all()));
    }


    #[PostMapping('getRobotList')]
    public function getRobotList(CustomerServiceRequest $request)
    {
        return $this->success($this->service->getRobotListByType($request->all()));
    }

    /**
     * 黑名单列表
     * @return ResponseInterface
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    #[PostMapping('getContactList')]
    public function getContactList(): ResponseInterface
    {
        return $this->success($this->service->getContactList($this->request->all()));
    }
}